package com.ssyx.common.exception;

import com.ssyx.common.result.Result;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * ClassName:GlobalExceptionHandler
 * Description:
 *
 * @Author kay
 * @Create 2024/4/22 16:49
 * @Version 1.0
 */
//AOP面向切面
@ControllerAdvice
public class GlobalExceptionHandler{


    //全局异常处理
    @ExceptionHandler(Exception.class) //异常处理器
    @ResponseBody //返回json数据
    public Result error(Exception e){
        e.printStackTrace();
        return Result.fail(null);
    }


    //自定义异常处理
    @ExceptionHandler(SsyxException.class)
    @ResponseBody
    public Result error(SsyxException e){
        return Result.build(null,e.getCode(),e.getMessage());
    }
}
